package com.cfuture08.home.action.backMenu;

import com.cfuture08.eweb4j.component.dwz.DWZUtil;
import com.cfuture08.eweb4j.component.dwz.vo.Menu;
import com.cfuture08.eweb4j.mvc.action.Action;
import com.cfuture08.eweb4j.mvc.action.ActionSupport;
import com.cfuture08.eweb4j.orm.dao.DAO;

;

public class AddBackMenu extends ActionSupport {
	private Menu menu;

	public String execute() {
		if (menu.getPid() > 0) {
			if (DAO.selectOne(Menu.class, new String[] { "id" }, new String[]{String.valueOf(menu.getPid())}) == null) {
				out.print(DWZUtil.getFailedJson("添加菜单" + menu.getName()
						+ "失败,该菜单名字父节点不存在"));
				return Action.AJAX;
			}
		}
		if (DAO.selectOne(menu, new String[] { "name" }) == null) {
			out.print(DAO.insert(menu) == true ? DWZUtil.getSuccessJson("添加菜单"
					+ menu.getName() + "成功", "xssycd", "showAllBackMenu.do",
					null) : DWZUtil.getFailedJson("添加菜单" + menu.getName()
					+ "失败"));
		} else {
			out.print(DWZUtil.getFailedJson("添加菜单" + menu.getName()
					+ "失败,该菜单名字已经存在"));
		}
		return Action.AJAX;
	}

	public Menu getMenu() {
		return menu;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}
}
